/**
* @Description: WoShop商城
* @Author: 梧桐
* @Copyright: 武汉一一零七科技有限公司©版权所有
* @Link: www.s1107.com
* @Contact: QQ:2487937004
*/
<template>
  <view class="index_class">
    <view class="goods_info">
      <image class="goods_cover" :src="goodsInfo.thumb_url" />
      <view style="padding:0 40upx 0 20upx;flex:1">
        <view class="goods_introduce">{{goodsInfo.goods_name}}</view>
        <view class="arrt-str"></view>
      </view>
    </view>
    <view class="rele-areat">
      <!--  app 端状态栏站位 -->
      <view class="input-text">
        <textarea v-model="textValue" name="" id="" cols="30" rows="10" placeholder="写点想要说的话吧..."></textarea>
        <view class="text-number">{{textValue.length}}/800</view>
      </view>
      
      <view class="addfile">
        <view class="grace-add-file">
          <view class="grace-add-btn" @tap="addImg" v-if="btnImg">
            <view>+</view>
            <view>添加照片</view>
          </view>
          <view class="garce-items" v-for="(item, index) in imgLists" :key="index">
            <image :src="item" mode="widthFix" :data-imgurl="item" @tap="showImgs"></image>
            <view class="grace-close" @tap="removeImg" :id="'grace-items-img-'+index"></view>
          </view>
        </view>
      </view>
      <view class="shoppin">
        <view class="feedback-star-view">
          <text>商品评分</text>
          <uni-rate class="unirate" value="0" @change="changeGoodsStar"></uni-rate>
        </view>
        <view class="feedback-star-view">
          <text>物流评分</text>
          <uni-rate class="unirate" value="0" @change="changeLogisticsStar"></uni-rate>
        </view>
        <view class="feedback-star-view">
          <text>服务评分</text>
          <uni-rate class="unirate" value="0" @change="changeServiceStar"></uni-rate>
        </view>
      </view>
      <view class="person-button" style="margin:0;background-color:#fff;padding-top:40upx">
        <button type="warn" class="btn" @click="getaddthorder">发 布</button>
      </view>
    </view>
  </view>
</template>


<script>
import uniRate from '../../components/uni-rate/uni-rate'
var maxNum = 9,
    _self;
export default {
  data() {
    return {
      order_id: '',
      goodsId: '',
      goodsInfo: '',
      list: [1, 2, 3, 4, 5, 6],
      imgLists: [],
      btnImg: true,
      graceSelectTips: [{
        name: 'php',
        value: '0',
        checked: true
      },
        {
          name: '.net',
          value: '1',
          checked: false
        },
        {
          name: 'java',
          value: '2',
          checked: false
        },
        {
          name: 'nodeJs',
          value: '3',
          checked: false
        },
        {
          name: '其他',
          value: '4',
          checked: false
        },
        {
          name: '其他',
          value: '5',
          checked: false
        },
        {
          name: '其他',
          value: '6',
          checked: false
        },
      ],
      textValue: '',
      goodsList: [],
      goddsName: [],
      pickValue: [],
      goodsStarValue: '0',
      logisticsStarValue: '0',
      serviceStarValue: '0',
      isClick: true
    }
  },
  components: {
    uniRate
  },
  onLoad(option) {
    _self = this;
    this.getOrderID(option);
    this.goodsId = option.goods_id;
    this.getGoodsInfo();
  },
  
  methods: {
    
    getOrderID(option) {
      this.order_id = option.id;
    },
    changeGoodsStar(e) {
      this.goodsStarValue = e.value;
    },
    changeLogisticsStar(e) {
      this.logisticsStarValue = e.value;
    },
    changeServiceStar(e) {
      this.serviceStarValue = e.value;
    },
    addImg: function() {
      var num = maxNum - _self.imgLists.length;
      if (num < 1) {
        return false;
      }
      
      uni.chooseImage({
        count: num,
        sizeType: ['compressed'],
        success: function(res) {
          _self.imgLists = _self.imgLists.concat(res.tempFilePaths);
          if (_self.imgLists.length >= maxNum) {
            _self.btnImg = false;
          }
          uni.hideLoading();
          
        }
      });
    },
    removeImg: function(e) {
      var index = e.currentTarget.id.replace('grace-items-img-', '');
      _self.imgLists.splice(index, 1);
      _self.imgLists = _self.imgLists;
      if (_self.imgLists.length < maxNum) {
        _self.btnImg = true;
      }
    },
    showImgs: function(e) {
      var currentImg = e.currentTarget.dataset.imgurl;
      uni.previewImage({
        urls: this.imgLists,
        current: currentImg
      })
    },
    /**
     * 图片上传
     */
    getuploadspic() {
      if (this.imgLists.length == 0) {
        this.$toast('请先上传图片')
        return false
      }
      return new Promise(resolve => {
        this.$http.getuploadspic(this.imgLists, '/api/find/uploadspic').then(res => {
          if (res.status == 200) {
            resolve(res.images)
          }
        })
      })
    },
    getGoodsInfo(){
      this.$http.getgoodsinfo({ goods_id: this.goodsId }).then(res => {
        if (res.status == 200) {
          this.goodsInfo = res.data.goodsinfo;
          console.log(res.data);
        }
      });
    },
    /**
     *提交审核
     */
    async getaddthorder() {
      if (this.textValue == '') {
        this.$toast('请输入评价内容')
        return false
      }
      if (this.goodsStarValue == '0') {
        this.$toast('请给商品打分')
        return false
      }
      if (this.logisticsStarValue == '0') {
        this.$toast('请给物流打分')
        return false
      }
      if (this.serviceStarValue == '0') {
        this.$toast('请给服务打分')
        return false
      }
      if (this.isClick == false) {
        this.$toast('-----')
        return false;
      }
      
      if (this.isClick) {
        this.isClick = false;
        this.$loading('上传中...');
        let str = await this.getuploadspic()
        
        let data = {
          content: this.textValue,
          goods_star: this.goodsStarValue,
          logistics_star: this.logisticsStarValue,
          service_star: this.serviceStarValue,
          pic: str.join(','),
          order_id: this.order_id,
          goods_id: this.goodsId,
        }
        
        this.$http.getaddgoodscomment(data).then(res => {
          if (res.status == 200) {
            this.$toast(res.mess)
          }
        });
        
      }
      
      setTimeout(() => {
        this.isClick = true;
        this.getback()
      }, 1500)
    },
  }
}
</script>

<style>
.goods_info {
  display: flex;
  justify-content: flex-start;
  padding: 15upx 30upx;
  background: #FFFFFF;
  margin-bottom: 3upx;
  color: #717171;
}
.goods_cover {
  width: 108upx;
  height: 108upx;
  border-radius: 10upx;
  border: dotted 1px #eeeeee;
}
</style>
